package com.sharding.sphere.demo.algorithm;

import com.google.common.collect.Range;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

/**
 * 负责切分库
 *
 * @author: shuguang.zhang
 * @date : 2021-06-04 17:02
 */
@Slf4j
public class TradeOrderDBComplexShardingStrategy implements ComplexKeysShardingAlgorithm<Long> {

    @Override
    public Collection<String> doSharding(Collection<String> databasesName, ComplexKeysShardingValue<Long> complexKeysShardingValue) {
        log.info("TradeOrderDBComplexShardingStrategy ---> tablesName:[{}] complexKeysShardingValue:[{}]", databasesName, complexKeysShardingValue);

        String logicTableName = complexKeysShardingValue.getLogicTableName();

        Map<String, Collection<Long>> columnNameAndShardingValuesMap = complexKeysShardingValue.getColumnNameAndShardingValuesMap();

        Map<String, Range<Long>> columnNameAndRangeValuesMap = complexKeysShardingValue.getColumnNameAndRangeValuesMap();

        return Arrays.asList("m1");
    }
}
